package com.gui.mianshiya.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gui.mianshiya.common.BaseResponse;
import com.gui.mianshiya.common.ResultUtils;
import com.gui.mianshiya.model.dto.collection.CollectionAddRequest;
import com.gui.mianshiya.model.entity.User;
import com.gui.mianshiya.model.dto.collection.WishCollectionQuestion;
import com.gui.mianshiya.model.vo.QuestionVO;
import com.gui.mianshiya.service.UserService;
import com.gui.mianshiya.service.WishCollectionService;
import io.github.lnyocly.ai4j.service.factor.AiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Title: CollectionsController
 * @Author quit
 * @Package com.gui.mianshiya.controller
 * @Date 2025/4/21 13:51
 * @description: 收藏
 */
@RestController
@RequestMapping("/collection")
@Slf4j
public class CollectionController {

    @Resource
    private UserService userService;


    @Resource
    private WishCollectionService wishCollectionService;
    /**
     * 添加题目
     *
     * @param collectionsAddRequest
     * @param request
     * @return
     */
    @PostMapping("/add")
    public BaseResponse<Boolean> addCollections(@RequestBody CollectionAddRequest collectionsAddRequest, HttpServletRequest request) {

        User loginUser = userService.getLoginUser(request);
        collectionsAddRequest.setUserId(loginUser.getId());
        int i = wishCollectionService.addCollectionUserId(collectionsAddRequest);
        if (i > 0) {
           return ResultUtils.success(true);
        }
      else return   ResultUtils.success(false);
    }

    @PostMapping ("/get/wishCollection")
    public BaseResponse<Boolean> getCollections(@RequestBody CollectionAddRequest collectionsAddRequest, HttpServletRequest request) {

        User loginUser = userService.getLoginUser(request);
        collectionsAddRequest.setUserId(loginUser.getId());
        int i = wishCollectionService.getCollectionUserId(collectionsAddRequest);
        if (i > 0) {
            return ResultUtils.success(true);
        }
        else return   ResultUtils.success(false);
    }

    @PostMapping ("/get/list/page/vo")
    public BaseResponse<Page<QuestionVO>> getCollectionList(@RequestBody WishCollectionQuestion wishCollectionQuestion, HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);
        wishCollectionQuestion.setUserId(loginUser.getId());
        return ResultUtils.success(wishCollectionService.getCollectionVoPage(wishCollectionQuestion, request));
    }
}
